﻿using ApiDemo.Core.Users;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace ApiDemo.Core.IdentityServer
{
    public class UserClaimsPrincipal: IUserClaimsPrincipalFactory<UserInfo>
    {
        //public async Task<ClaimsPrincipal> CreateAsync(UserInfo user)
        //{
        //    var principal = await CreateAsync(user);
        //    ((ClaimsIdentity)principal.Identity).AddClaims(new[] {
        //new Claim(ClaimTypes.Name, user.UserName)
        //    });
        //    return principal;
        //}
        public async Task<ClaimsPrincipal> CreateAsync(UserInfo user)
        {
            //var claims = await _userManager.GetClaimsAsync(user);
            var claims = new ClaimsIdentity(new Claim[] { new Claim("username", user.UserName) });
            //var claims = new ClaimsIdentity( );
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claims);
            return await Task.FromResult(claimsPrincipal);

        }
    }
}
